package com.xsb.customview.progressbar;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    RectangleProgressView progress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progress = findViewById(R.id.progressbar);
        progress.setMaxCount(100);
        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                for (int i = 0; i <= progress.getMaxCount(); i++) {
                    Message msg = new Message();
                    msg.arg1 = i;
                    msg.what = 0x01;
                    handler.sendMessage(msg);
                    try {
                        //每隔0.1秒进度前进1
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 0x01) {
                progress.setCurrentCount(msg.arg1);
            }
        }
    };
}